package com.ext.aic.utils;

import android.content.Context;

import androidx.annotation.StringRes;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.SimpleCallback;

public class LoadingUtils {

    private static BasePopupView loadingPopup;

    public static void showLoading(Context context, @StringRes int resId) {
        if (loadingPopup == null) {
            loadingPopup = new XPopup.Builder(context)
                    .dismissOnBackPressed(false) // 禁用返回键关闭
                    .dismissOnTouchOutside(false) // 禁用点击外部关闭
                    .setPopupCallback(new SimpleCallback() {
                        @Override
                        public void onDismiss(BasePopupView popupView) {
                            loadingPopup = null;
                        }
                    })
                    .asLoading(context.getString(resId));
        }
        if (!loadingPopup.isShow()) {
            loadingPopup.show();
        }
    }

    public static void hideLoading() {
        if (loadingPopup != null && loadingPopup.isShow()) {
            loadingPopup.dismiss();
        }
    }
}
